﻿using HrEFCore;
using HrEFCore.Models;
using HrIService;
using HrService;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.CodeAnalysis.Elfie.Serialization;
using System.Net.Mail;
// 导入发送邮件所需的命名空间
using System.Net;
using System.Net.Mail;
using System.Net.Http;
using System.Text;
using Microsoft.Extensions.Caching.Distributed;
using System.Text.Json;

namespace HrUI.Controllers
{
	public class ERController : Controller
	{

		private readonly MyDbContext myDbContext;
		private readonly ERService eRService;
		private readonly CMKService cMKService;
		private readonly CMService cMService;
		private readonly CPCService cPCService;
		private readonly CFTKService cFTKService;
		private readonly IWebHostEnvironment environment;
		private readonly EIService eIService;
		private readonly UserService userService;
        private readonly HFService hFService;
        private readonly IDistributedCache memoryCache;
        private readonly ILogger<HomeController> logger;

        public ERController(MyDbContext myDbContext, ERService eRService, CMKService cMKService
			, CMService cMService, CPCService cPCService, CFTKService cFTKService, IWebHostEnvironment environment,
			EIService eIService, UserService userService,HFService hFService, IDistributedCache memoryCache, ILogger<HomeController> logger)
		{
			this.myDbContext = myDbContext;
			this.eRService = eRService;
			this.cMKService = cMKService;
			this.cMService = cMService;
			this.cPCService = cPCService;
			this.cFTKService = cFTKService;
			this.environment = environment;
			this.eIService = eIService;
			this.userService = userService;
            this.hFService = hFService;
            this.memoryCache = memoryCache;
            this.logger = logger;
        }

		//跳转页面
		public async Task<IActionResult> Add(short id)
		{
			string uname = HttpContext.Session.GetString("UTrueName");
			HttpContext.Session.SetInt32("MreId", id);
			//EMR emr = await eRService.EMRById(id);
			//ViewData.Model = emr;
			ViewBag.uname = uname;
			await xllb();
			return View();
		}
		public async Task<IActionResult> EMRById()
		{
			short MreId = (short)HttpContext.Session.GetInt32("MreId");
			EMR emr = await eRService.EMRById(MreId);
			return Json(emr);
		}
		[HttpPost]
		public async Task<IActionResult> Add(ER er)//添加逻辑
		{
			//将照片存储在session中
			er.HumanPicture = HttpContext.Session.GetString("url");

			CMK cmk = await eRService.SelectCMKById(er.HumanMajorKindId);
			er.HumanMajorKindName = cmk.MajorKindName;//获取职位分类名称

			CM cm = await eRService.SelectCMById(er.HumanMajorId);
			er.HunmaMajorName = cm.MajorName;//获取职位名称
											 //获取图片路径
			string tp = HttpContext.Session.GetString("url");
			er.HumanPicture = tp;
			int row = await eRService.AddERAsync(er);
			//用eRService的AddERAsync方法将er对象添加到数据库

			if (row > 0)
			{
				//添加成功 跳转筛选页面
				return RedirectToAction("JLSX");
			}
			else
			{
				//失败留在添加页面
				return RedirectToAction("Add");
			}
		}
		//简历筛选查询的条件页面
		public async Task<IActionResult> JLSX()
		{

			await xllb();
			return View();
		}

        
        
		//简历筛选的查询按钮  开始 
		public async Task<IActionResult> SelectByTime(ER er, DateTime startDate, DateTime endDate)
		{
			//DateTime startdate = startDate;
			//DateTime enddate = endDate;
			if (startDate != DateTime.MinValue)
			{
				HttpContext.Session.SetString("startDate", startDate.ToString());
			}
			else
			{
				HttpContext.Session.SetString("startDate", "");
			}
			if (endDate != DateTime.MinValue)
			{
				HttpContext.Session.SetString("endDate", endDate.ToString());
			}
			else
			{
				HttpContext.Session.SetString("endDate", "");
			}
			if (er.HumanMajorKindId == null)
			{
				HttpContext.Session.SetString("HumanMajorKindName", "");
			}
			else
			{
				CMK cmk = await eRService.SelectCMKById(er.HumanMajorKindId);
				er.HumanMajorKindName = cmk.MajorKindName;//职位分类名称
				HttpContext.Session.SetString("HumanMajorKindName", er.HumanMajorKindName);
			}

			if (er.HumanMajorId == null)
			{
				HttpContext.Session.SetString("HunmaMajorName", "");
			}
			else
			{
				CM cm = await eRService.SelectCMById(er.HumanMajorId);
				er.HunmaMajorName = cm.MajorName;//职位名称	
				HttpContext.Session.SetString("HunmaMajorName", er.HunmaMajorName);
			}


			string uname = HttpContext.Session.GetString("UTrueName");
			ViewBag.uname = uname;

			//List<ER> ers = await eRService.SelectKaiShiER(name);
			//ViewBag.er = ers;




			return View();
		}

        //[ResponseCache(Duration = 60)]
        //推荐，根据id查看登记的数据
        public async Task<IActionResult> TuiJian(short id)
		{
            //存session中
            string uname = HttpContext.Session.GetString("UTrueName");
			ViewBag.uname = uname;
			//通过方法查询id展示数据
			ER er = await eRService.SelectERById(id);
			ViewBag.img = er.HumanPicture;
			ViewData.Model = er;
			//调用下拉列表
			await xllb();
			//返回视图
			return View();
		}

		//推荐成功 修改 状态 推荐人 推荐时间
		public async Task<IActionResult> TuiJianUpdate(ER er)
		{
			//CMK cmk = await hFService.SelectCMKById(hf.HumanMajorKindId);
			//hf.HumanMajorKindName = cmk.MajorKindName;//职位分类名称

			//CM cm = await hFService.SelectCMById(hf.HumanMajorId);
			//hf.HunmaMajorName = cm.MajorName;//职位名称
			EI ei = new EI()
			{
				HumanName = er.HumanName,
				InterviewAmount = 1,
				HumanMajorKindId = er.HumanMajorKindId,
				HumanMajorKindName = er.HumanMajorKindName,
				HumanMajorId = er.HumanMajorId,
				HunmaMajorName = er.HunmaMajorName,
				ImageDegree = "",
				NativeLanguageDegree = "",
				ForeignLanguageDegree = "",
				ResponseSpeedDegree = "",
				EQDegree = "",
				IQDegree = "",
				MultiQualityDegree = "",
				Register = "",
				Checker = "",
				RegisteTime = DateTime.Now,
				CheckTime = DateTime.Now,
				ResumeId = er.ResId,
				Result = "",
				InterviewComment = "",
				CheckComment = "",
				InterviewStatus = 1,
				CheckStatus = 0
			};
			int result = await eIService.AddEI(ei);
			int row = await eRService.Update(er);
			if (row > 0 && result>0)
			{
				return RedirectToAction("YXSX");
			}
			else
			{
				return RedirectToAction("TuiJian", new { id = er.ResId });
			}

		}

		//模糊查询
		public async Task<IActionResult> SelectFYByName(int currentPage, int pageSize)
		{
			string start = HttpContext.Session.GetString("startDate");
			string end = HttpContext.Session.GetString("endDate");
			string huname = HttpContext.Session.GetString("HumanName");
			string MajorKindName = HttpContext.Session.GetString("HumanMajorKindName");
			string MajorName = HttpContext.Session.GetString("HunmaMajorName");
			StringBuilder where = new StringBuilder();

			if (start != "" && end != "")
			{
				where.Append($" and RegistTime between '{start}' and '{end}'");
			}
			else if (start != "" && end == "")
			{
				where.Append($" and RegistTime > '{start}'");
			}
			else if (start == "" && end != "")
			{
				where.Append($" and RegistTime < '{end}'");
			}
			else
			{
				where.Append($" ");
			}

			if (huname == null)
			{
				where.Append($" and HumanName like '%%'");
			}
			else
			{
				where.Append($" and HumanName like '%{huname}%'");
			}
			if (MajorKindName == null)
			{
				where.Append($" and HumanMajorKindName like '%%'");
			}
			else
			{
				where.Append($" and HumanMajorKindName like '%{MajorKindName}%'");
			}
			if (MajorName == null)
			{
				where.Append($" and HunmaMajorName like '%%'");
			}
			else
			{
				where.Append($" and HunmaMajorName like '%{MajorName}%'");
			}
			FenYe2<ER> fy = await eRService.SelectFYTJER(currentPage, pageSize, where.ToString());
			return Json(fy);
		}
		//条件查询的页面 有效筛选
		public async Task<IActionResult> YXSX()
		{
			await xllb();
			return View();
		}

		//模糊查询 时间 职位  
		public async Task<IActionResult> YXCX(ER er, DateTime startDate, DateTime endDate)
		{
			//DateTime startdate = startDate;
			//DateTime enddate = endDate;
			if (startDate != DateTime.MinValue)
			{
				HttpContext.Session.SetString("startDate", startDate.ToString());
			}
			else
			{
				HttpContext.Session.SetString("startDate", "");
			}
			if (endDate != DateTime.MinValue)
			{
				HttpContext.Session.SetString("endDate", endDate.ToString());
			}
			else
			{
				HttpContext.Session.SetString("endDate", "");
			}
			if (er.HumanMajorKindId == null)
			{
				HttpContext.Session.SetString("HumanMajorKindName", "");
			}
			else
			{
				CMK cmk = await eRService.SelectCMKById(er.HumanMajorKindId);
				er.HumanMajorKindName = cmk.MajorKindName;//职位分类名称
				HttpContext.Session.SetString("HumanMajorKindName", er.HumanMajorKindName);
			}

			if (er.HumanMajorId == null)
			{
				HttpContext.Session.SetString("HunmaMajorName", "");
			}
			else
			{
				CM cm = await eRService.SelectCMById(er.HumanMajorId);
				er.HunmaMajorName = cm.MajorName;//职位名称	
				HttpContext.Session.SetString("HunmaMajorName", er.HunmaMajorName);
			}
			string uname = HttpContext.Session.GetString("UTrueName");
			ViewBag.uname = uname;

			return View();
		}

		//条件查询
		public async Task<IActionResult> SelectFYByName2(int currentPage, int pageSize)
		{
			string start = HttpContext.Session.GetString("startDate");
			string end = HttpContext.Session.GetString("endDate");
			string huname = HttpContext.Session.GetString("HumanName");
			string MajorKindName = HttpContext.Session.GetString("HumanMajorKindName");
			string MajorName = HttpContext.Session.GetString("HunmaMajorName");
			StringBuilder where = new StringBuilder();
			//条件查询 状态大于等于1 
			where.Append(" and CheckStatus>=1 ");

			if (start != "" && end != "")
			{
				where.Append($" and RegistTime between '{start}' and '{end}'");
			}
			else if (start != "" && end == "")
			{
				where.Append($" and RegistTime > '{start}'");
			}
			else if (start == "" && end != "")
			{
				where.Append($" and RegistTime < '{end}'");
			}
			else
			{
				where.Append($" ");
			}

			if (huname == null)
			{
				where.Append($" and HumanName like '%%'");
			}
			else
			{
				where.Append($" and HumanName like '%{huname}%'");
			}
			if (MajorKindName == null)
			{
				where.Append($" and HumanMajorKindName like '%%'");
			}
			else
			{
				where.Append($" and HumanMajorKindName like '%{MajorKindName}%'");
			}
			if (MajorName == null)
			{
				where.Append($" and HunmaMajorName like '%%'");
			}
			else
			{
				where.Append($" and HunmaMajorName like '%{MajorName}%'");
			}
			FenYe2<ER> fy = await eRService.SelectFYTJER(currentPage, pageSize, where.ToString());
			return Json(fy);
		}
		//根据id查看 推荐成功的数据
		public async Task<IActionResult> YXSXCX(short id)
		{
			string uname = HttpContext.Session.GetString("UTrueName");
			//ViewBag.uname = uname;
			ER er = await eRService.SelectERById(id);
			//ViewBag.img = er.HumanPicture;
			ViewData.Model = er;
			//await xllb();
			return View();
		}
		public async Task<IActionResult> Index2(FenYe2<ER> fy)
		{
			fy = await eRService.SelectAllFYERAsync(fy);
			return Json(fy);
		}

		


		public async Task xllb()//下拉列表
		{
			List<CMK> list = await cMKService.InquireAll();
			SelectList selectListItems = new SelectList(list, "MajorKindId", "MajorKindName");
			ViewBag.cmk = selectListItems;//职位分类

			List<CM> list2 = await cMService.CMSelectAsync();
			SelectList selectListItems2 = new SelectList(list2, "MajorId", "MajorName");
			ViewBag.cm = selectListItems2;//职位名称

			List<CPC> list3 = await cPCService.Inquirenationnal();
			SelectList selectListItems3 = new SelectList(list3, "AttributeName", "AttributeName");
			ViewBag.gj = selectListItems3;//国籍

			List<CPC> list4 = await cPCService.InquireNation();
			SelectList selectListItems4 = new SelectList(list4, "AttributeName", "AttributeName");
			ViewBag.mz = selectListItems4;//民族

			List<CPC> list5 = await cPCService.InquireZjxy();
			SelectList selectListItems5 = new SelectList(list5, "AttributeName", "AttributeName");
			ViewBag.zjxy = selectListItems5;//宗教信仰

			List<CPC> list6 = await cPCService.InquireZzmm();
			SelectList selectListItems6 = new SelectList(list6, "AttributeName", "AttributeName");
			ViewBag.zzmm = selectListItems6;//政治面貌

			List<CPC> list7 = await cPCService.Inquirexl();
			SelectList selectListItems7 = new SelectList(list7, "AttributeName", "AttributeName");
			ViewBag.xl = selectListItems7;//学历

			List<CPC> list8 = await cPCService.InquireJynx();
			SelectList selectListItems8 = new SelectList(list8, "AttributeName", "AttributeName");
			ViewBag.jynx = selectListItems8;//教育年限

			List<CPC> list9 = await cPCService.InquireZy();
			SelectList selectListItems9 = new SelectList(list9, "AttributeName", "AttributeName");
			ViewBag.xlzy = selectListItems9;//专业

			List<CPC> list10 = await cPCService.InquireTc();
			SelectList selectListItems10 = new SelectList(list10, "AttributeName", "AttributeName");
			ViewBag.tc = selectListItems10;//特长

			List<CPC> list11 = await cPCService.InquireAh();
			SelectList selectListItems11 = new SelectList(list11, "AttributeName", "AttributeName");
			ViewBag.ah = selectListItems11;//爱好

			List<SS> list16 = await hFService.SSXLAsync();
			SelectList selectListItems15 = new SelectList(list16, "StandardId", "StandardName");
			ViewBag.xc = selectListItems15;//薪酬
		}

		//级联 一级
		public async Task<List<JiLian>> GetFirstKinds()
		{
			List<CFFK> cf = await cFTKService.CFFKSelectAsync();
			List<JiLian> jl = new List<JiLian>();
			foreach (CFFK item in cf)
			{
				JiLian jilian = new JiLian()
				{
					value = item.FirstKindId,
					label = item.FirstKindName,
					children = await GetSecondKinds(item.FirstKindId)
				};
				jl.Add(jilian);
			}
			return jl;
		}
		//二级
		public async Task<List<JiLian>> GetSecondKinds(string id)
		{
			List<CFSK> cs = await cFTKService.CFSKLDAsync(id);
			List<JiLian> jl = new List<JiLian>();
			foreach (CFSK item in cs)
			{
				JiLian jiLian = new JiLian()
				{
					value = item.SecondKindId,
					label = item.SecondKindName,
					children = await GetThirdKinds(item.SecondKindId)
				};
				jl.Add(jiLian);
			}
			return jl;
		}

		//三级
		public async Task<List<JiLian>> GetThirdKinds(string id)
		{
			List<CFTK> cf = await cFTKService.CFTKLDAsync(id);
			List<JiLian> jl = new List<JiLian>();
			foreach (CFTK item in cf)
			{
				JiLian jiLian = new JiLian()
				{
					value = item.ThirdKindId,
					label = item.ThirdKindName,
				};
				jl.Add(jiLian);
			}
			return jl;
		}
		public IActionResult IRAR(int page = 1, int pageSize = 2)
		{
			//跳转面试管理->面试结果登记
			var result = eRService.GetPagedERView(page, pageSize);
			ViewData.Model = result;

			// 设置分页相关数据
			ViewData["CurrentPage"] = page;
			ViewData["PageSize"] = pageSize;
			ViewData["TotalRows"] = myDbContext.ERView.Count();

			return View();
		}
		public IActionResult InterviewScreening(int page = 1, int pageSize = 3)
		{
			//跳转面试结果筛选页面
			var result = eRService.GetPagedERView2(page, pageSize);
			ViewData.Model = result;

			// 设置分页相关数据
			ViewData["CurrentPage"] = page;
			ViewData["PageSize"] = pageSize;
			ViewData["TotalRows"] = myDbContext.ERView2.Count();

			return View();
		}
		public IActionResult JobApplication(int page = 1, int pageSize = 3)
		{
			//跳转录用管理->录用申请页面
			var result = eRService.Hired(page, pageSize);
			ViewData.Model = result;

			// 设置分页相关数据
			ViewData["CurrentPage"] = page;
			ViewData["PageSize"] = pageSize;
			ViewData["TotalRows"] = myDbContext.ERHired.Count();

			return View();
		}
		public IActionResult ApprovalEmployment(int page = 1, int pageSize = 2)
		{
			//跳转录用管理->录用审批页面
			var result = eRService.Hired2(page, pageSize);
			ViewData.Model = result;

			// 设置分页相关数据
			ViewData["CurrentPage"] = page;
			ViewData["PageSize"] = pageSize;
			ViewData["TotalRows"] = myDbContext.ERHired2.Count();
			return View();
		}
		public async Task<IActionResult> RecruitmentInquiry(int page = 1, int pageSize = 3)
		{
			//跳转录用管理->录用查询页面
			var result = eRService.Hired3(page, pageSize);
			ViewData.Model = result;

			// 设置分页相关数据
			ViewData["CurrentPage"] = page;
			ViewData["PageSize"] = pageSize;
			ViewData["TotalRows"] = myDbContext.ERHired3.Count();
			return View();
		}
		public async Task<IActionResult> HFAdd(int page=1,int pageSize = 3)
		{
			//跳转录用管理->录用查询页面
			var result = eRService.Hired3(page, pageSize);
			ViewData.Model = result;

			// 设置分页相关数据
			ViewData["CurrentPage"] = page;
			ViewData["PageSize"] = pageSize;
			ViewData["TotalRows"] = myDbContext.ERHired3.Count();
			return View();
		}
		public async Task<IActionResult> DJ(short resId)
		{
			//跳转面试结果登记页面
			ERCheckIn eRCheckIn = await eRService.CheckIn(resId);
			string uname = HttpContext.Session.GetString("UTrueName");
			ViewBag.uname = uname;
			ViewData.Model = eRCheckIn;
			return View();
		}
		public async Task<IActionResult> InterviewSX(short resId)
		{
			//跳转面试筛选页面
			ERSift eRSift = await eRService.ERSiftEI(resId);
			ViewData.Model = eRSift;
			string uname = HttpContext.Session.GetString("UTrueName");
			ViewBag.uname = uname;
			await xllb();
			return View();
		}
		public async Task<IActionResult> actionResult(short resId)
		{
			//跳转录用管理中的录用申请页面
			ERHiredApplication eRHiredApplication = await eRService.ERHiredApplicationEI(resId);
			ViewData.Model = eRHiredApplication;


			return View();
		}
		public async Task<IActionResult> HiredApproval(short resId)
		{
			//跳转录用管理中的录用审批页面
			ERHiredApproval eRHiredApproval = await eRService.ERHiredApproval(resId);
			ViewData.Model = eRHiredApproval;
			return View();
		}
		public async Task<IActionResult> HiredInquiry(short resId)
		{
			//跳转录用管理中的录用查询页面
			ERHiredInquire eRHiredInquire = await eRService.ERHiredInquire(resId);
			ViewData.Model = eRHiredInquire;
			return View();
		}
		public async Task<IActionResult> ReviseERHiredApplication(ER er)
		{
			//录用管理->录用申请中的申请
			short id = er.ResId;
			string passCheckComment = er.PassCheckComment;
			int rulst = await eRService.RevisePassCheckComment(id, passCheckComment);
			if (rulst > 0)
			{
				return RedirectToAction("JobApplication");
			}
			else
			{
				return RedirectToAction("actionResult", new { resId = id });
			}
		}
		public async Task<IActionResult> ReviseERHiredApproval(ER er)
		{
			//录用管理->录用审批中的审批
			short id = er.ResId;
			string passPassComment = er.PassPassComment;
			int result = await eRService.RevisePassPassComment(id, passPassComment);
			if (result > 0)
			{
				// 如果审批意见是“通过”，则发送邮件
				if (passPassComment == "通过")
				{
					string toEmailAddress = er.HumanEmail;  // 获取员工的邮箱地址
					string subject = "录用申请审批通过通知";  // 邮件主题
					string body = "恭喜您，您的录用申请已通过审批！";  // 邮件内容

					// 发送邮件
					using (MailMessage mail = new MailMessage())
					{
						mail.From = new MailAddress("3367669477@qq.com");  // 发件人邮箱地址
						mail.To.Add(toEmailAddress);  // 收件人邮箱地址
						mail.Subject = subject;  // 设置邮件主题
						mail.Body = body;  // 设置邮件内容

						using (SmtpClient smtp = new SmtpClient("smtp.qq.com"))
						{
							smtp.Port = 587;  // 设置 SMTP 服务器端口
							smtp.Credentials = new NetworkCredential("3367669477@qq.com", "tufzxupvepwqdafb");  // 设置发件人邮箱用户名和密码
							smtp.EnableSsl = true;  // 启用 SSL 加密

							// 发送邮件
							try
							{
								smtp.Send(mail);
							}
							catch (Exception ex)
							{
								// 发送邮件失败，处理异常
								Console.WriteLine("邮件发送失败：" + ex.Message);
							}
						}
					}
				}

				return RedirectToAction("ApprovalEmployment");
			}
			else
			{
				return RedirectToAction("HiredApproval", new { resId = id });
			}



		}
		public async Task<IActionResult> AddSift(ER eRSift)
		{
			short id = eRSift.ResId;//id
			string checker = eRSift.Checker;//推荐人
			DateTime checkTime = (DateTime)eRSift.CheckTime;//推荐时间
			string passCheckComment = eRSift.PassCheckComment;//录用申请审核意见(面试状态)

			
			string attachmentName = HttpContext.Session.GetString("url");//档案附件

			short zhi = 0;
			if (passCheckComment == "建议面试")
			{
				zhi = 3;
			}
			else if (passCheckComment == "建议笔试")
			{
				zhi = 4;
			}
			else if (passCheckComment == "建议录用")
			{
				zhi = 5;
			}
			else if (passCheckComment == "删除简历")
			{
				zhi = 6;
			}


			int DG = await eIService.Revise(id, checkTime, checker);
			if (DG > 0)
			{
				int SC = await eRService.Revise(id, passCheckComment, attachmentName, checker);
				if (SC > 0)
				{
					if (zhi > 0)
					{
						int xgER = await eRService.ReviseInterviewStatus(id, zhi);
						int xgEI = await eIService.ReviseInterviewStatus(id, zhi);
						if (xgER > 0 && xgEI > 0)
						{
							return RedirectToAction("InterviewScreening");
						}
						else
						{
							await Console.Out.WriteLineAsync("修改人力资源--招聘管理--面试管理--面试筛选中的面试状态");
							return RedirectToAction("SX", new { resId = id });
						}
					}
					else
					{
						await Console.Out.WriteLineAsync("判断面试状态是否有值");
						return RedirectToAction("SX", new { resId = id });
					}
				}
				else
				{
					await Console.Out.WriteLineAsync("修改人力资源--招聘管理--面试管理--面试筛选中的ER表的档案附件和图片");
					return RedirectToAction("SX", new { resId = id });
				}
			}
			else
			{
				await Console.Out.WriteLineAsync("修改人力资源--招聘管理--面试管理--面试筛选中的EI表的推荐人和推荐时间");
				return RedirectToAction("SX", new { resId = id });
			}

		}
		public async Task<IActionResult> AddEI(EI eI)
		{
			//面试登记逻辑
			short zhi2 = 2;
			short id = eI.ResumeId;
			eI.InterviewStatus = zhi2;
			eI.Result = "通过";
			eI.CheckComment = "";
			int XG = await eIService.UpdateEIByResumeId(eI);
			if (XG > 0)
			{
				int xgER = await eRService.ReviseInterviewStatus(id, zhi2);
				if (xgER > 0)
				{
					return RedirectToAction("IRAR");
				}
				else
				{
					return RedirectToAction("DJ", new { resId = id });
				}
			}
			else
			{
				return RedirectToAction("DJ", new { resId = id });
			}
		}
		[HttpGet]
		public IActionResult FYCX(int page, int pageSize)
		{
			var result = eRService.GetPagedERView(page, pageSize);

			return Json(new { erList = result, totalRows = myDbContext.ERView.Count() });
		}
		[HttpGet]
		public IActionResult FYCX2(int page, int pageSize)
		{
			var result = eRService.GetPagedERView2(page, pageSize);

			return Json(new { erList = result, totalRows = myDbContext.ERView2.Count() });
		}
		[HttpGet]
		public IActionResult HiredFYCX(int page, int pageSize)
		{
			var result = eRService.Hired(page, pageSize);

			return Json(new { erList = result, totalRows = myDbContext.ERHired.Count() });
		}
		[HttpGet]
		public IActionResult Hired2FYCX(int page, int pageSize)
		{
			var result = eRService.Hired2(page, pageSize);

			return Json(new { erList = result, totalRows = myDbContext.ERHired2.Count() });
		}
		[HttpGet]
		public IActionResult Hired3FYCX(int page, int pageSize)
		{
			var result = eRService.Hired3(page, pageSize);

			return Json(new { erList = result, totalRows = myDbContext.ERHired3.Count() });
		}
		// 模糊查询页面
		public async Task<IActionResult> Fuzzy()
		{
			// 创建并返回视图

			return View();
		}

		//关键字的模糊查询
		public async Task<IActionResult> Getname(string condition)
		{
			IEnumerable<ER> erList = eRService.GetERByCondition(condition);
			return View(erList);
		}

		public async Task<IActionResult> GetNames(string id)//根据职位分类拿到职位名称
		{
			List<CM> cm = await eRService.SelectNameLD(id);
			return Json(cm);
		}
		public async Task<IActionResult> Update(ER er)//点击修改按钮，修改字段
		{
			er.CheckStatus = 0;//复核状态要改变
			int row = await eRService.Update(er);
			if (row > 0)
			{
				return RedirectToAction("CXUpd");
			}
			else
			{
				return RedirectToAction("Upd", new { id = er.ResId });
			}
		}

		public async Task xllb2()//下拉列表
		{
			List<CMK> list = await cMKService.InquireAll();
			SelectList selectListItems = new SelectList(list, "MajorKindId", "MajorKindName");
			ViewBag.cmk = selectListItems;//职位分类

			List<CM> list2 = await cMService.CMSelectAsync();
			SelectList selectListItems2 = new SelectList(list2, "MajorId", "MajorName");
			ViewBag.cm = selectListItems2;//职位名称
		}


		//筛选编辑
		public IActionResult Sift()
		{
			return View();
		}

		[HttpPost]
		public IActionResult WJSC(IFormFileCollection file)
		{
			foreach (var item in file)
			{
				string name = DateTime.Now.ToString("yyyyMMddHHmmssfff"); // 生成唯一的文件名
				string ext = Path.GetExtension(item.FileName); // 获取文件扩展名
				string path = $"Uploader/{DateTime.Now.ToString("yyyy/MM/dd/")}" + name + ext; // 构建文件保存的路径
				var uploads = Path.Combine(environment.WebRootPath, path); // 获取文件保存的完整路径
				HttpContext.Session.SetString("url", path);
				(new FileInfo(uploads)).Directory.Create(); // 创建保存文件的目录（如果不存在）
				using (var stream = new FileStream(uploads, FileMode.Create))
				{
					item.CopyTo(stream); // 将文件保存到指定路径
				}
			}
			return Content("ok");
		}

		[HttpPost]
		public IActionResult WJSC2(IFormFileCollection file)//文件上传
		{
			foreach (var item in file)
			{
				//生成文件名
				string name = DateTime.Now.ToString("yyyyMMddHHmmssfff");
				//获取后缀名
				string ext = item.FileName.Substring(item.FileName.LastIndexOf('.'));
				//设置上传路径
				string path = $"OtherUploader/{DateTime.Now.ToString("yyyy/MM/dd/")}" + name + ext;
				//生成文件的绝对路径
				var uploads = Path.Combine(environment.WebRootPath, path);
				//ViewBag.url = uploads;
				HttpContext.Session.SetString("url2", path);
				//创建上传文件对应的文件夹
				(new FileInfo(uploads)).Directory.Create();
				using (var stream = new FileStream(uploads, FileMode.CreateNew))
				{
					item.CopyTo(stream);//图片上传
										//TempData["name"] = name + ext;//保存图片的值
				}
				//return uploads;
			}
			return Content("ok");

		}

	}
}
